package com.personal.website.lottery.web.service.impl;

import com.personal.website.lottery.web.dao.ArticleMapper;
import com.personal.website.lottery.web.dao.CommentMapper;
import com.personal.website.lottery.web.model.Comment;
import com.personal.website.lottery.web.model.CommentExample;
import com.personal.website.lottery.web.service.CommentService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by 10171225 on 2016/3/28.
 */
@Service("commentService")
public class CommentServiceImpl implements CommentService {

    @Resource
    private CommentMapper commentMapper;

    public List<Comment> getCommentsByArcicleId(int articleId) {
        CommentExample example = new CommentExample();
        example.createCriteria().andArticleIdEqualTo(articleId);
        return this.commentMapper.selectByExample(example);
    }

    public void insertComment(Comment comment) {
        this.commentMapper.insert(comment);
    }

    public List<Integer> getCommentArticleIds(int userId) {
        CommentExample example = new CommentExample();
        example.createCriteria().andUserIdEqualTo(userId);
        List<Comment> commentList = this.commentMapper.selectByExample(example);
        List<Integer> articleIdList = new ArrayList<Integer>();
        for(Comment comment: commentList){
            articleIdList.add(comment.getArticleId());
        }
        return articleIdList;
    }
}
